Completed
Pull Request — develop (#231)
by
unknown
04:08 queued 01:42
created

$gaOptoutLinks.click   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 4
nc 6
nop 1
dl 0
loc 18
rs 9.2
c 2
b 0
f 0
1
/* global dataFlyntFeatureGoogleAnalytics, Cookies */
2
3
import $ from 'jquery'
4
import 'file-loader?name=vendor/js-cookie.js!js-cookie/src/js.cookie'
5
6
const $gaOptoutLinks = $('.globalAction-optoutGa')
7
const data = dataFlyntFeatureGoogleAnalytics
8
9
const alreadyOptedOut = getOptoutCookie()
10
11
if (alreadyOptedOut) {
12
  $gaOptoutLinks.remove()
13
  window['ga-disable-' + data.gaId] = true
14
} else {
15
  $gaOptoutLinks.on('click', function (e) {
16
    e.preventDefault()
17
    let confirmOptout = false
0 ignored issues
show
Unused Code introduced by
The assignment to variable confirmOptout seems to be never used. Consider removing it.
Loading history...
18
19
    if (data.confirm) {
20
      confirmOptout = window.confirm(data.confirm)
21
    } else {
22
      confirmOptout = true
23
    }
24
25
    if (confirmOptout) {
26
      window['ga-disable-' + data.gaId] = true
27
      if (data.success) {
28
        window.alert(data.success)
29
      }
30
      setOptoutCookie()
31
    }
32
  })
33
}
34
35
function setOptoutCookie () {
36
  Cookies.set('disableGa', true)
37
  $gaOptoutLinks.remove()
38
}
39
40
function getOptoutCookie () {
41
  return Cookies.get('disableGa')
42
}
43